package com.nondo.rdp.finance.domain.course;

import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.Length;

import com.nondo.rdp.auth.domain.User;
import com.nondo.rdp.core.domain.attach.Attach;
import com.nondo.rdp.core.domain.base.BaseEntity;
import com.nondo.rdp.finance.config.DbConfig;

/**
 * 求知-课程
 */
@Entity
@Table(name = DbConfig.DEFAULT_TABLE_PREFIX + "course", indexes = {@Index(columnList = "type,name,recommend,pclassifyId,classifyId,recommendDate,publishDate")})
public class Course extends BaseEntity {
    private static final long serialVersionUID = -5591180597470716846L;
    private Long id;// 主键
    private String name;// 课程名称
    private String description;// 课程简介
    private Attach descImg; // 简介图片
    private Integer type; // 类型：0=专辑课程|普通课程=1
    private String teacher;// 讲师
    private String introduction; //讲师简介
    private User user; // 发布人
    private int free;// 是否免费
    private float price;// 当前价格
    private float origPrice;// 原始价格
    private int auditStatus;// 审核状态0：未审核；1：通过;2:驳回
    private Attach mainImg; // 封面图片
    private Date publishDate;// 发布时间
    private Integer status;// 上架状态0:下架；1：上架
    private Integer recommend;// 是否推荐
    private Date recommendDate;// 推荐日期
    private float rate;// 平均评分分数
    private int sortNum;// 排序值
    private Integer home;// 是否放置首页 0|1
    private Integer pclassifyId; // 父分类ID
    private Integer classifyId; // 子分类ID
    private Long readNum; // 浏览量
    private Integer mold;//课程类型，0=视频，1=音频
    private Integer albumId;//采集中的专辑ID
    
    // 扩展字段
    private String searchId; //前台搜索的ID
    private String readNumSortDirection;// 排序值排序方向
    private String sortNumSortDirection;// 阅读量排序方向

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @NotNull(message = "课程名称不能为空")
    @Length(min = 1, max = 32, message = "课程名称长度不能超过32个字符")
    @Column(name = "name", length = 32)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @NotNull(message = "课程简介不能为空")
    @Length(min = 10, max = 255, message = "课程简介长度不少于10个字符且不能超过255个字符")
    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @NotNull(message = "分享图片不能为空")
    @OneToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "desc_img")
    public Attach getDescImg() {
        return descImg;
    }

    public void setDescImg(Attach descImg) {
        this.descImg = descImg;
    }

    @NotNull(message = "类型不能为空")
    @Column(columnDefinition = "int default 0", nullable = false)
    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    @NotNull(message = "讲师姓名不能为空")
    public String getTeacher() {
        return teacher;
    }

    public void setTeacher(String teacher) {
        this.teacher = teacher;
    }

    @NotNull(message = "讲师简介不能为空")
    @Length(min = 10, max = 255, message = "讲师简介长度不少于10个字符且不能超过255个字符")
    public String getIntroduction() {
        return introduction;
    }

    public void setIntroduction(String introduction) {
        this.introduction = introduction;
    }

    @OneToOne
    @JoinColumn(name = "uid")
    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @Column(columnDefinition = "int default 1", nullable = false)
    public int getFree() {
        return free;
    }

    public void setFree(int free) {
        this.free = free;
    }

    public float getPrice() {
        return price;
    }

    public void setPrice(float price) {
        this.price = price;
    }

    public float getOrigPrice() {
        return origPrice;
    }

    public void setOrigPrice(float origPrice) {
        this.origPrice = origPrice;
    }

    @Column(columnDefinition = "int default 0", nullable = false)
    public int getAuditStatus() {
        return auditStatus;
    }

    public void setAuditStatus(int auditStatus) {
        this.auditStatus = auditStatus;
    }

    @NotNull(message = "封面图片不能为空")
    @OneToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "main_img")
    public Attach getMainImg() {
        return mainImg;
    }

    public void setMainImg(Attach mainImg) {
        this.mainImg = mainImg;
    }

    public Date getPublishDate() {
        return publishDate;
    }

    public void setPublishDate(Date publishDate) {
        this.publishDate = publishDate;
    }

    @Column(columnDefinition = "int default 1", nullable = false)
    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    @Column(columnDefinition = "int default 0", nullable = false)
    public Integer getRecommend() {
        return recommend;
    }

    public void setRecommend(Integer recommend) {
        this.recommend = recommend;
    }

    @Temporal(TemporalType.DATE)
    @Column(length = 10)
    public Date getRecommendDate() {
        return recommendDate;
    }

    public void setRecommendDate(Date recommendDate) {
        this.recommendDate = recommendDate;
    }

    @Column(columnDefinition = "float default 0.0", scale = 1, nullable = false)
    public float getRate() {
        return rate;
    }

    public void setRate(float rate) {
        this.rate = rate;
    }

    @Column(columnDefinition = "int default 0", nullable = false)
    public int getSortNum() {
        return sortNum;
    }

    public void setSortNum(int sort) {
        this.sortNum = sort;
    }

    @Column(columnDefinition = "int default 0", nullable = false)
    public Integer getHome() {
        return home;
    }

    public void setHome(Integer home) {
        this.home = home;
    }

    @NotNull(message ="必须选择一个分类" )
    @Column(columnDefinition = "int default 0", nullable = false)
	public Integer getPclassifyId() {
		return pclassifyId;
	}

	public void setPclassifyId(Integer pclassifyId) {
		this.pclassifyId = pclassifyId;
	}

	@Column(columnDefinition = "int default 0")
	public Integer getClassifyId() {
		return classifyId;
	}

	public void setClassifyId(Integer classifyId) {
		this.classifyId = classifyId;
	}

	@Column(columnDefinition = "int default 0")
	public Long getReadNum() {
		return readNum;
	}

	public void setReadNum(Long readNum) {
		this.readNum = readNum;
	}

	@Column(columnDefinition = "int default 0")
    public Integer getMold() {
        return mold;
    }

    public void setMold(Integer mold) {
        this.mold = mold;
    }

    public Integer getAlbumId() {
        return albumId;
    }

    public void setAlbumId(Integer albumId) {
        this.albumId = albumId;
    }

    @Transient
    public String getSearchId() {
        return searchId;
    }

    public void setSearchId(String searchId) {
        this.searchId = searchId;
    }

	@Transient
	public String getReadNumSortDirection() {
		return readNumSortDirection;
	}

	public void setReadNumSortDirection(String readNumSortDirection) {
		this.readNumSortDirection = readNumSortDirection;
	}

	@Transient
	public String getSortNumSortDirection() {
		return sortNumSortDirection;
	}

	public void setSortNumSortDirection(String sortNumSortDirection) {
		this.sortNumSortDirection = sortNumSortDirection;
	}
    
}
